﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;

namespace PushpinClusterer.Datatemplate
{
    public abstract class DataTemplateSelector : ContentControl
    {
        public virtual DataTemplate SelectTemplate<T>(
            object item, DependencyObject container) where T : IClusteredGeoObject
        {
            return null;
        }

        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);

            Type type = newContent.GetType().GetGenericArguments()[0];

            MethodInfo method = TypeExtensions.GetMethodWp7Workaround(typeof(PushpinTemplateSelector), "SelectTemplate");

            //MethodInfo[] methods = typeof(PushpinTemplateSelector).GetMethods();// ("SelectTemplate");

            //foreach (MethodInfo method in methods)
            //{
            //}

            MethodInfo generic = method.MakeGenericMethod(type);
            ContentTemplate = generic.Invoke(this, new object[] { newContent, this}) as DataTemplate; 


           ///ContentTemplate = SelectTemplate(newContent, this);
        }

        
    }
}
